package com.top.ruizhong.main.host

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.View
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.FileUtils
import com.blankj.utilcode.util.PhoneUtils
import com.module.lemlin.base.BaseAbstractActivity
import com.top.ruizhong.R
import com.top.ruizhong.app.RZApplication
import com.top.ruizhong.mode.manager.getDiskCacheDirectory
import com.top.ruizhong.popup.DialogHintPopup
import com.top.ruizhong.popup.PasswordSettingPopup
import kotlinx.android.synthetic.main.activity_main_setting.*
import java.lang.StringBuilder

class MainSettingActivity : BaseAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, MainSettingActivity::class.java)
            activity.startActivity(intent)
        }
    }


    private val cacheHintPopup: DialogHintPopup by lazy {
        DialogHintPopup(context = this,
            onConfirm = {
                cacheHintPopup.dismiss()
            },
            onCancel = {
                cacheHintPopup.dismiss()
            })
    }

    private val pwdSettingPopup: PasswordSettingPopup by lazy {
        PasswordSettingPopup(context = this, onGetCode = { phone ->
            //获取验证码
        }, onConfirm = { smsCode, password, confirmPassword ->

        })
    }

    override val layoutResId: Int
        get() = R.layout.activity_main_setting

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, view = flSettingBar)
    }

    override fun initView() {

        RZApplication.userInfoMe()?.password_set?.let {
            tvSettingPwdStatus.text = if (it != 1) "去设置" else "修改"
        }
        tvSettingFileSize.text =
            FileUtils.getDirSize(getDiskCacheDirectory(this as Context))
        tvSettingVersion.text =
            StringBuilder().append("V").append(AppUtils.getAppVersionName())

        ivSettingBack.setOnClickListener {
            finish()
        }

        flSettingCache.setOnClickListener {
            cacheHintPopup.setTextTitle("温馨提示")
                .setTextMessage("是清除缓存数据？")
                .setTextCancel("否")
                .setTextConfirm("是")
                .showPopupWindow()
        }

        flSettingPassword.setOnClickListener {
            pwdSettingPopup.setPhone(RZApplication.userInfoMe()?.mobile)
                .setTitle("访问密码设置")
                .showPopupWindow()
        }

        tvSettingAbout.setOnClickListener {
            MainRichTextActivity.open(activity = this, title = "关于我们")
        }

        tvSettingPactUser.setOnClickListener {
            MainRichTextActivity.open(activity = this, title = "用户协议")
        }

        tvSettingPactPrivate.setOnClickListener {
            MainRichTextActivity.open(activity = this, title = "隐私协议")
        }

        tvSettingProblem.setOnClickListener {
            MainRichTextActivity.open(activity = this, title = "常见问题")
        }

    }
}